home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Hyper / Ss-Sz / StrFunc.cpt / String Functions / card_2952.txt < prev    next >
Encoding:
Text File  |  1988-01-03  |  3.6 KB  |  115 lines

  1. -- card: 2952 from stack: in
  2. -- bmap block id: 3666
  3. -- flags: 0000
  4. -- background id: 2639
  5. -- name: 
  6. ----- HyperTalk script -----
  7. --
  8. -- Yen's String Functions
  9. --
  10. -- ¬© copyright 1988 by Yen Applecia
  11. -- this is shareware.  to use these routines you should
  12. -- mail a check for $3 to:
  13. --
  14. --      Yen Applecia
  15. --      1284 Chilanian Lane
  16. --      San Jose, CA 95120
  17. --
  18.  
  19. -- RIGHT(STRING, NUM)
  20. -- extracts "num" number of characters from the string
  21. -- from the right side, i.e. from the beginning of the string.
  22. --
  23. function right string, num
  24. return char 1 to num of string
  25. end right
  26.  
  27. -- LEFT(STRING, NUM)
  28. -- extracts "num" number of characters from the string
  29. -- from the left side, i.e. from the end of the string.
  30. --
  31. function left string, num
  32. put (length of string) into len
  33. return char (len - num + 1) to len of string
  34. end left
  35.  
  36. -- MID(STRING, START, NUM)
  37. -- extracts "num" number of characters from the string
  38. -- starting at the "start"th character.
  39. --
  40. function mid string, start, num
  41. return char start to (start + num - 1) of string
  42. end mid
  43.  
  44. -- BREAKKEY(STRING, KEY)
  45. -- give a "string" and a "key", this routine breaks the string up
  46. -- to three parts, the part of the string that came before the
  47. -- key, the key itself, and the part of the string that came
  48. -- after the key.  These three components are stuffed into a
  49. -- single item with three lines, each component on its own line.
  50. --
  51. function breakKey string, key
  52. put (length of string) into len
  53. put (length of key) into keylen
  54. put offset(key, string) into off
  55. put key into line two of Result
  56. put right(string, off-1) into line one of Result
  57. put char (off + keylen) to len of string into line three of Result
  58. return Result
  59. end breakKey
  60.  
  61. -- NOLEADING(STRING)
  62. -- get rid of leading spaces in "string".
  63. --
  64. function noLeading string
  65. repeat while (char 1 of string is space)
  66.   delete first char of string
  67. end repeat
  68. return string
  69. end noLeading
  70.  
  71. -- NOTRAILING(STRING)
  72. -- get rid of trailing spaces in "string".
  73. --
  74. function noTrailing string
  75. repeat while (last char of string is space)
  76.   delete last char of string
  77. end repeat
  78. return string
  79. end noTrailing
  80.  
  81. -- TRIM(STRING)
  82. -- get rid of leading and trailing spaces
  83. --
  84. function Trim string
  85. put noLeading(string) into string
  86. put noTrailing(string) into string
  87. return string
  88. end Trim
  89.  
  90. ---------------------------------------------------------------------
  91.  
  92. on openCard
  93.   hide message
  94. end openCard
  95.  
  96.  
  97.  
  98.  
  99. -- part 3 (field)
  100. -- low flags: 01
  101. -- high flags: 0004
  102. -- rect: left=9 top=171 right=334 bottom=503
  103. -- title width / last selected line: 0
  104. -- icon id / first selected line: 0 / 0
  105. -- text alignment: 0
  106. -- font id: 4
  107. -- text size: 9
  108. -- style flags: 0
  109. -- line height: 12
  110. -- part name: 
  111.  
  112.  
  113. -- part contents for card part 3
  114. ----- text -----
  115. This is a collection of string functions that I've written for a stack that I'm developing.  I thought it might be useful to some of you.  The string functions are ordinary hypertalk functions, unlike XFCNs.  To use it all you have to do is copy them from the script of this card to wherever you want to use them.  The reason for writing this function was one of my hypercard projects that involved heavy text processing.  I thought it would have been nice if I could use functions that I've already been familiar with in BASIC, even though BASIC is commonly thought of as an ungly language.  Things like "left()", "right()", "mid()" or so useful to me that I simply cannot do without them.  Other functions such as "noLeading()" and "noTrailing" are useful to me to process user inputs.  Surely as time goes on I will write and use more text routines.  I will pass them around, too, but right now this is all I have.